if(!anthill) var anthill = {};
if(!anthill.maps) anthill.maps = {};

anthill.maps.Geocoder = function(directions) {
  if($.type(directions) !== 'array') {
	  directions = [directions];
  }
  this.directions = directions;
}

anthill.maps.Geocoder.prototype.geocode = function(callback) {
  var geocoder = new google.maps.Geocoder();
  var responses = [];
  var gcElem = this;
  var setResponses = function(response, status) {
	  if(!response) {
	    response = {};
	  }
	  response.dirObj = gcElem.directions[responses.length];
	  response.status = status;
	  responses.push(response);
	  if(gcElem.directions.length <= responses.length) {
		  callback(responses);
	  } else {
		  var address = "";
		  if($.type(gcElem.directions[responses.length]) === 'string') {
			  address = gcElem.directions[responses.length];
		  } else if (gcElem.directions[responses.length].address && $.type(gcElem.directions[responses.length].address) === 'string') {
			  address = gcElem.directions[responses.length].address;
		  }
		  setTimeout(function() {
		    geocoder.geocode({'address': address}, setResponses);
		  }, 100);
	  }
  };
  if(this.directions.length > 0) {
	  if($.type(this.directions[0]) === 'string') {
		  address = this.directions[0];
	  } else if (this.directions[0].address && $.type(this.directions[0].address) === 'string') {
		  address = this.directions[0].address;
	  }
	  geocoder.geocode({'address': address}, setResponses);
  } else {
	  callback(responses);
  }
};